package com.example.algorithm.greedy;

import java.util.Arrays;

/**
 * @author : zhy
 * @since : 2022/8/31
 * 用最少的箭射击气球
 */
public class ShutQiQiu {


    public int findMinArrowShots(int[][] points) {
        //这个其实就是见 point[0]里面的数值看作一个一维数组   x[0] x[1]这样来比较
        //所以下面比较的内容就是比较 point[0][0] 与 point[1][0]的值  根据前缀来排序
        Arrays.sort(points,(x,y)->Integer.compare(x[0],y[0]));
        int count=1;
        int bound=points[0][1];
        int len= points.length;
        for(int i=1;i<len;i++)
        {
            if(points[i][0]>bound) {
                count++;
                bound=points[i][1];
            } else {
                bound=Math.min(bound,points[i][1]);
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int [][]can={{1,2}, {3,4},{5,6}};
        ShutQiQiu shutQiQiu = new ShutQiQiu();
        System.out.println(shutQiQiu.findMinArrowShots(can));
    }
}
